package com.dada.config;

import com.dangdang.ddframe.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//@Profile({"dev", "test", "prod"})
@ConditionalOnExpression("'${elastic.job.server-lists}'.length() > 0")
public class ElasticJobConfig {
    @Bean
    @ConfigurationProperties(prefix = "elastic.job")
    public ZookeeperConfiguration zkConfig() {
        return new ZookeeperConfiguration();
    }

    @Bean(initMethod = "init")
    public ZookeeperRegistryCenter regCenter() {
        return new ZookeeperRegistryCenter(zkConfig());
    }
}